package com.fudan.sys.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fudan.framework.base.BaseDao;
import com.fudan.framework.base.DaoService;
import com.fudan.sys.dao.UserDao;
import com.fudan.sys.entity.User;
import com.fudan.sys.security.PasswordUtils;

@Service
public class UserService extends DaoService<User>{

	@Autowired
	private UserDao userDao;

	public User getUserByName(String name) {
		return userDao.findByUsername(name);
	}
	
	public Map<String,Object> getUserInfo(Integer id) {
		Map<String, Object> userInfo = userDao.getUserInfo(id);
		return userInfo;
	}
	
	@Override
	public Boolean add(User t) {
		if(t.getPassword() == null) {
			t.setPassword(PasswordUtils.encrypt("123321"));
		}
		return super.add(t);
	}

	public Integer countUser() {
		return userDao.countUser();
	}

	public List<Map<String,Object>> getUserList(int page,int size) {
		return userDao.getUserList((page-1)*size,size);
	}
	public List<Map<String,Object>> getUserListByUserName(String name,int page,int size) {
		return userDao.getUserListByUserName(name,(page-1)*size,size);
	}
	@Override
	protected BaseDao<User> injectDao() {
		return userDao;
	}
}
